package com.autumn.xa.common.util;

import com.autumn.xa.common.vo.LabelTreeVO;
import com.autumn.xa.common.vo.LabelTreeResponseBodyVO;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: TreeUtil
 *
 * @Description:
 * @Author: wangqiuyang
 * @Date: 2021/12/29 下午3:13
 * History:
 * <author>          <time>          <version>          <desc>
 * wangqiuyang    2021/12/29 下午3:13   @Version 1.0        描述
 */
public class TreeUtil {
    public static final int LABEL_ENUM_LIST = 0;
    public static final int LABEL_VALUE_LIST = 1;

    /**
     * Description: 拷贝树
     * <p> 如果 mode 取值 LABEL_ENUM_LIST , 拷贝树的子节点为标签枚举值 身份类型树专用</p>
     * <p> 如果 mode 取值 LABEL_VALUE_LIST , 拷贝树的子节点为标签值 企业画像用</p>
     * @param oldVO 被拷贝的树
     * @param newVO 拷贝后的树
     * @param mode 取值 LABEL_ENUM_LIST ｜ LABEL_VALUE_LIST
     * @return: void
     * @author: wangqiuyang
     * @Date: 2021/12/5 下午3:49
     */
    public static void copyTreeLabelTreeVO(LabelTreeResponseBodyVO oldVO , LabelTreeVO newVO , int mode){

//        if (oldVO.getChildrenList() == null || oldVO.getChildrenList().isEmpty()) {
//            return;
//        }

        newVO.setLabelName(oldVO.getLabelName());
        newVO.setLabelCode(oldVO.getLabelCode());
        newVO.setLabelLevel(oldVO.getLabelLevel());

        // 判断取枚举还是值
        if (mode == TreeUtil.LABEL_ENUM_LIST) {
            if (oldVO.getLabelEnumValues() != null && !oldVO.getLabelEnumValues().isEmpty()) {
                newVO.setEnumValueList(oldVO.getLabelEnumValues());
            }
        } else if (mode == TreeUtil.LABEL_VALUE_LIST) {
            if (oldVO.getObjLabelValues() != null && !oldVO.getObjLabelValues().isEmpty()) {
                newVO.setLabelValueList(oldVO.getObjLabelValues());
            }
        }

        List<LabelTreeVO> newChildList = new ArrayList<>();
        newVO.setChildrenList(newChildList);

        // 暂时去掉 等待调试
        if (oldVO.getChildrenList() == null || oldVO.getChildrenList().isEmpty()) {
            return;
        }

        List<LabelTreeResponseBodyVO> childList = oldVO.getChildrenList();

        for (LabelTreeResponseBodyVO child : childList) {
            LabelTreeVO tree = new LabelTreeVO();
            newVO.getChildrenList().add(tree);
            // 递归
            copyTreeLabelTreeVO(child , tree , mode);
        }
    }
}
